from django.db import models


# Create your models here.
# 商品分类模型
class ProductCategoryModel(models.Model):
    name = models.CharField(max_length=50, verbose_name="类别名称", unique=True)
    description = models.CharField(max_length=200, verbose_name="分类描述")

    def __str__(self):
        return self.name

    class Meta:
        db_table = "product_category"
        verbose_name = "商品分类"
        verbose_name_plural = "商品分类"


# 商品品牌模型
class ProductBrandModel(models.Model):
    name = models.CharField(max_length=100, verbose_name="品牌名称", unique=True, null=False, blank=False)
    country = models.CharField(max_length=50, verbose_name="国家", null=False, blank=False)
    description = models.CharField(max_length=200, verbose_name="品牌简介", null=False, blank=False)
    logo = models.CharField(max_length=200, verbose_name="标志", null=False, blank=False)

    def __str__(self):
        return self.name

    class Meta:
        db_table = "product_brand"
        verbose_name = "商品品牌"
        verbose_name_plural = "商品品牌列表"


# 商品表
class ProductModel(models.Model):
    name = models.CharField(max_length=50, verbose_name="商品名称", null=False, blank=False)
    price = models.DecimalField(max_digits=9, decimal_places=2, verbose_name="商品单价价", null=False, blank=False)
    count = models.IntegerField(verbose_name="商品库存存", null=False, blank=False)
    manufacturer = models.CharField(max_length=255, verbose_name="生产厂家家", null=False, blank=False)
    production_date = models.DateField(verbose_name="生产日日期", null=False, blank=False)
    expiry_date = models.DateField(verbose_name="有效期期至", null=False, blank=False)
    category = models.ForeignKey(ProductCategoryModel, on_delete=models.CASCADE, verbose_name="商品分类",
                                 related_name='products')  # 假设 Category 模型已经存在
    brand = models.ForeignKey(ProductBrandModel, on_delete=models.CASCADE, verbose_name="商品品牌",
                              related_name='products')  # 假设 Brand 模型已经存在
    description = models.CharField(max_length=255, verbose_name="商品描述", null=True, blank=True)
    specifications = models.CharField(max_length=200, verbose_name="商品规格", null=True, blank=True)
    features = models.CharField(max_length=200, verbose_name="商品特点", null=True, blank=True)
    images = models.ImageField(upload_to='product_images/', verbose_name="商品图片", null=True, blank=True)
    video = models.URLField(verbose_name="商品视频", null=True, blank=True)
    # 增加三个字段好评（100）  中评（30） 差评（10）
    good_review = models.CharField(max_length=100, verbose_name="好评", null=True, blank=True)
    middle_review = models.CharField(max_length=30, verbose_name="中评",null=True,blank=True)
    bad_review = models.CharField(max_length=10, verbose_name="差评", null=True, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        db_table = "product"
        verbose_name = "商品"
        verbose_name_plural = verbose_name
